#include('header.html')
<script type="text/javascript">
    changeTab('阶段记录');

    function gotoPage(e, page) {
        var pages   = ${pages.totalPages};
        var stageId = $('select[name="stage_id"]').val();
        var shopId  = $('select[name="shop_id"]').val();

        var query = "";
        if (stageId !== '') {
            query += ("&stage_id=" + stageId);
        }
        if (shopId !== '') {
            query += ("&shop_id=" + shopId);
        }

        var status = $(e).parent().attr("class");
        if (page > 0 && page <= pages && page !== ${pages.number + 1} &&
            status !== "active") {
            location.href = '/admin/count?pageNo=' + page + query;
        }
    }

    function show_count(stageId, shopId) {
        if (stageId === null) {
            alert("没有相关详情！");
        } else
            location.href = '/admin/record?stage_id=' + stageId + "&shop_id=" + shopId;
    }
    
    function StageCountExport() {
        var stageId = $('select[name="stage_id"]').val();
        var shopId  = $('select[name="shop_id"]').val();
        window.open("/excel/export/stageCount?stageId=" + stageId + "&shopId=" + shopId, '_self');
    }
</script>

<div class="plan-xcontent">
    <div>
        <div class="col-lg-12 col-xs-12">
            <a class="text-black" href="/admin/count">
                <h4><span class="fa fa-hand-o-right"></span> 阶段记录</h4>
            </a>
            <div style="padding: 15px 5px 0;" class="pull-right">
                <button onclick="StageCountExport();" class="btn btn-warning btn-sm">导出</button>
                <form style="display: inline-block;" id="record-search" method="get">
                    <div class="input-group min-min-input pull-left">
                        <select name="shop_id" class="form-control min-min-select">
                            <option value="">-- 全部公司 --</option>
                            #for(Shop shop : shops)
                            <option value="${shop.id}" ${shop_id?(shop_id.asInt()==shop.id?'selected':''):''}>${shop.name}</option>
                            #end
                        </select>
                    </div>
                    <div class="input-group min-min-input pull-left">
                        <select name="stage_id" class="form-control min-min-select">
                            <option value="">-- 全部阶段 --</option>
                            #for(Stage st : stages)
                            <option value="${st.id}" ${stage_id?(stage_id.asInt()==st.id?'selected':''):''}>${st.name}</option>
                            #end
                        </select>
                    </div>
                    <button class="btn btn-info btn-sm">搜索</button>
                </form>
            </div>
        </div>
        <div>
            <div class="col-lg-12 col-xs-12">
                <table class="table table-striped">
                    <thead class="bg-color-x">
                    <tr>
                        <td>排名</td>
                        <td>物业公司</td>
                        <td>打分阶段</td>
                        <td>总评</td>
                        <td>增长率</td>
                        <td style="width: 140px;">操作</td>
                    </tr>
                    </thead>
                    <tbody>
                        #for(StageCount sc : pages.content)
                        <tr>
                            <td>${for.index}</td>
                            <td>${sc.shop.name ?! ''}</td>
                            <td>${sc.stage.name ?! ''}</td>
                            <td>${sc.total.format('0.00') ?! '0.00'}</td>
                            <td>${sc.rate.format('0.00') ?! '0'}%</td>
                            <td>
                                <button onclick="show_count(${sc.stage ? sc.stage.id : 'null'}, ${sc.shop.id});"
                                        class="btn btn-xs btn-success">评分详情</button>
                            </td>
                        </tr>
                        #else
                        <tr>
                            <td align="center" colspan="6">暂无数据</td>
                        </tr>
                        #end
                    </tbody>
                </table>
                <!-- 分页按钮 -->
                #if(pages.totalPages > 1)
                <div class="col-lg-12 col-xs-12 text-center">
                    <ul style="margin: 0;" class="pagination pagination-sm">
                        <!--<li onclick="gotoPage(this, 1)"><a href="javascript:">首页</a></li>
                        #for(int i : range(1, pages.totalPages))
                        <li class="${i == pages.number + 1 ? 'active':''}"
                            onclick="gotoPage(this, ${i})"><a href="javascript:">${i}</a></li>
                        #end
                        <li onclick="gotoPage(this, ${pages.totalPages})"><a href="javascript:">尾页</a></li>-->
                    </ul>
                    <span style="padding-top: 15px; font-size: 12px;" class="pull-right">
                        共${pages.totalPages}页，${pages.totalElements}条数据
                    </span>
                </div>
                #end
            </div>
        </div>
    </div>
</div>

#include('footer.html')